package com.lhn.service.impl;

import com.lhn.domain.Account;
import com.lhn.service.AccountService;
import com.lhn.dao.AccountDao;
import com.lhn.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author lhn
 * @date 2024-08-23 14:26
 */
@Service
public class AccountServiceImpl implements AccountService{

    @Autowired
    private AccountDao accountDao;

    @Autowired
    private LogService logService;

    @Override
    public void transfer(String from, String to, double money) {
        try {
            accountDao.inMoney(to, money);
            int i = 1/0;
            accountDao.outMoney(from, money);
        } finally {
            logService.log(from, to, money);
        }
    }

    @Override
    public Account findAccountByName(String name) {
        Account account = accountDao.findByName(name);
        if (account != null) {
            return account;
        }
        else {
            return new Account(0, "查询失败", 0);
        }
    }
}
